const md5 = require('js-md5');
const axios = ({
  url,
  method = 'GET',
  data = {},
  tipName = '加载中'
}) => {
  const header = {}
  if (uni.getStorageSync('token')) {
    header.token = uni.getStorageSync('token') //登录后拿到token值
  }
  return new Promise((resolve, reject) => {
    uni.showLoading({
      title: tipName,
    })
   uni.request({
      url: url.substring(0, 1) === '/' ? `${baseUrl}${url}` : `${url}`, // 兼容baseUrl不同的情况，可以通过填写完整路径
      method,
      data,
      header,
      success: res => {
        resolve(res)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        uni.hideLoading()
      }
    })
  })
}


import Vue from 'vue';

// import axios from 'axios';

let publicKey = 'bosihuiwen@!bj';

export default {
  get(url, params) {
    // axios.get(url, {
    // 	params: params
    // })
    // .then(response => {
    // 	resolve(response.data);
    // })
    // .catch(err => {
    // 	reject(err)
    // })
    return axios({
      url: url,
      method: 'GET',
      data: params,
    })
  },

  ValidSignStr(dictionary) {
    var sortKeys = Object.keys(dictionary).sort();
    var str = "";
    var i = 0;
    for (var key in sortKeys) {
      console.log(sortKeys[key] !== 'Birthday','bb')
      if (sortKeys[key] !== 'Birthday') {
        if ((dictionary[sortKeys[key]] === 0 && dictionary[sortKeys[key]] !== '') || (dictionary[sortKeys[key]] !== '' && dictionary[sortKeys[key]] !== null && dictionary[sortKeys[key]] != undefined)) {
          str += sortKeys[key] + "=" + dictionary[sortKeys[key]] + "&";
        }
      }

    }
    if (str != "") {
      str = str.substr(0, str.length - 1);
    }
    var Sign = md5(str.toLowerCase());
    // var Sign
    return Sign;
  },
  post(url, data) {
    // let PostData = data;
    // delete PostData.Sign
    // Vue.set(PostData, 'AppKey', publicKey);
    // let Sign = this.ValidSignStr(PostData);
    // Vue.set(PostData, 'Sign', Sign);
    // delete PostData.AppKey
    // return new Promise((resolve, reject) => {
    // 	axios.post(url, PostData)
    // 		.then(response => {
    // 			resolve(response);
    // 		}, err => {
    // 			reject(err)
    // 		})
    // })
    let PostData = data;
    delete PostData.Sign
    Vue.set(PostData, 'AppKey', publicKey);
    let Sign = this.ValidSignStr(PostData);
    Vue.set(PostData, 'Sign', Sign);
    delete PostData.AppKey
    return axios({
      url: url,
      method: 'POST',
      data: PostData,
    })
  }
}



const baseUrl = 'http://bjlm.bosihw.cn'
